package form;

import database.DBO;
import widget.QueryTable;
import widget.TLabel;
import widget.TRadioGroup;
import widget.TTextField;

import javax.swing.*;
import java.awt.*;

/**
 * Created by LLAP on 2017/12/13.
 * Copyright (c) 2017 LLAP. All rights reserved.
 */
public class OfferAdd extends Form {
    public OfferAdd() {
        super("房源出售/出租信息登记", 800, 500);
        this.setMaxWidth(800);
        QueryTable t = new QueryTable();
        t.addRow().add(new TLabel("房源出售/出租信息登记"));
        t.addRow().add(new TRadioGroup("offer", new Object[] {"出租", "出售"}, "登记类型", true));
        t.addRow().add(new TTextField("address", "房屋地址", true));
        t.addRow().add(new TTextField("builtyear", "建成年份", true));
        t.addRow().add(new TTextField("district", "所在片区"));
        t.addRow().add(new TTextField("area", "建筑面积（平方米）", true));
        t.addRow().add(new TRadioGroup("type", new Object[] {"平层", "复式", "跃式"}, "户型", true));
        t.addRow().add(new TRadioGroup("decor", new Object[] {"精装", "简装", "毛坯"}, "装修", true));
        t.addRow().setHeight(100).add(
                new TRadioGroup("direction", new Object[] {"东", "西", "南", "北"}, "房屋朝向", true)
        );
        t.addRow().add(new TTextField("price", "底价（万元）", true));
        this.setLayout(new BorderLayout(10, 10));
        this.add("Center", t.pack());
        JButton btn = new JButton("Dump");
        this.add("South", btn);
        btn.addActionListener(e -> {
            try {
                DBO db = new DBO();
//                System.out.println(t.getData().toString());
                db.create("offer", t.getData());
                JOptionPane.showMessageDialog(null, "添加成功");
                db.close();
                dispose();
            }
            catch (Exception ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage());
            }
        });
        //this.pack();
    }

}
